package com.aidex.biz.service.impl;

import java.util.List;

import com.aidex.biz.domain.BizAssessInfo;
import com.aidex.biz.service.BizAssessInfoService;
import com.aidex.common.annotation.DataScope;
import com.github.pagehelper.PageInfo;
import com.aidex.common.core.domain.entity.SysUser;
import com.aidex.common.core.domain.entity.SysDept;
import com.aidex.common.core.service.BaseServiceImpl;
import com.aidex.framework.cache.DeptUtils;
import com.aidex.framework.cache.UserUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.aidex.biz.mapper.BizAssessToDeptMapper;
import com.aidex.biz.domain.BizAssessToDept;
import com.aidex.biz.service.BizAssessToDeptService;
import org.springframework.transaction.annotation.Transactional;
import com.aidex.common.utils.NumberUtils;

/**
 * 考核部门Service业务层处理
 * @author sean
 * @email 2074844820@qq.com
 * @date 2024-11-29
 */
@Service
@Transactional(readOnly = true)
public class BizAssessToDeptServiceImpl extends BaseServiceImpl<BizAssessToDeptMapper, BizAssessToDept> implements BizAssessToDeptService
{
    private static final Logger log = LoggerFactory.getLogger(BizAssessToDeptServiceImpl.class);

    @Autowired
    private BizAssessInfoService assessInfoService;

    /**
     * 获取单条数据
     * @param bizAssessToDept 考核部门
     * @return 考核部门
     */
    @Override
    public BizAssessToDept get(BizAssessToDept bizAssessToDept)
    {
        BizAssessToDept dto = super.get(bizAssessToDept);
        return dto;
    }

    /**
     * 获取单条数据
     * @param id 考核部门id
     * @return 考核部门
     */
    @Override
    public BizAssessToDept get(String id)
    {
        BizAssessToDept dto = super.get(id);
        return dto;
    }


    /**
     * 查询考核部门列表
     * @param bizAssessToDept 考核部门
     * @return 考核部门
     */
    @Override
    @DataScope(userAlias = "a",deptAlias = "a")
    public List<BizAssessToDept> findList(BizAssessToDept bizAssessToDept)
    {
        return super.findList(bizAssessToDept);
    }

    /**
     * 分页查询考核部门列表
     * @param bizAssessToDept 考核部门
     * @return 考核部门
     */
    @Override
    @DataScope(userAlias = "a",deptAlias = "a")
    public PageInfo<BizAssessToDept> findPage(BizAssessToDept bizAssessToDept)
    {
        return super.findPage(bizAssessToDept);
    }

    /**
     * 保存考核部门
     * @param bizAssessToDept
     * @return 结果
     */
    @Override
    @Transactional(readOnly = false)
    public boolean save(BizAssessToDept bizAssessToDept)
    {
        if(super.save(bizAssessToDept)){
            if("3".equals(bizAssessToDept.getStatus())){
                // 更新考核状态
                BizAssessInfo assessInfo = new BizAssessInfo();
                assessInfo.setId(bizAssessToDept.getAssessId());
                assessInfo=assessInfoService.get(assessInfo);
                if(null!=assessInfo){
                    if(assessInfo.getTotal()==assessInfo.getPingfentotal()){
                        // 总数等于评分数 评分完成
                        assessInfo.setStatus("3");
                        assessInfoService.updateStatus(assessInfo);
                    }
                }
            }
            return true;
        }
        return false;
    }


    /**
     * 删除考核部门信息
     * @param bizAssessToDept
     * @return 结果
     */
    @Override
    public boolean remove(BizAssessToDept bizAssessToDept)
    {
        return super.remove(bizAssessToDept);
    }

    /**
     * 批量删除考核部门
     * @param ids 需要删除的考核部门ID
     * @return 结果
     */
    @Transactional(readOnly = false)
    @Override
    public int deleteBizAssessToDeptByIds(String[] ids)
    {
        return mapper.deleteBizAssessToDeptByIds(ids);
    }

    /**
     * 获取最大编号
     * @param bizAssessToDept 考核部门
     * @return 结果
     */
    @Override
    public int findMaxSort(BizAssessToDept bizAssessToDept)
    {
        return NumberUtils.nextOrder(mapper.findMaxSort(bizAssessToDept));
    }

    @Override
    public int deleteByAssessId(BizAssessToDept bizAssessToDept) {
        return mapper.deleteByAssessId(bizAssessToDept);
    }

    @Override
    public int insertBatch(BizAssessToDept list) {
        return mapper.insertBatch(list);
    }

    @Override
    @Transactional(readOnly = false)
    public int updateStatus(BizAssessToDept bizAssessToDept) {
        return  mapper.updateStatus(bizAssessToDept);
    }

    @Override
    public List<BizAssessToDept> findListByFu(BizAssessToDept bizAssessToDept) {
        return mapper.findListByFu(bizAssessToDept);
    }
}
